package com.buyingtickets.service.impl;

import com.buyingtickets.dao.StopoverStationDao;
import com.buyingtickets.entity.StopoverStation;
import com.buyingtickets.entity.Train;
import com.buyingtickets.entity.TrainNumber;
import com.buyingtickets.service.StopoverStationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author bwj
 * @date 2021/6/24 9:09
 */
@Service
public class StopoverStationServiceImpl implements StopoverStationService {
    @Resource
    private StopoverStationDao stopoverStationDao;

    @Override
    public List<StopoverStation> queryById(Train train) {
        return stopoverStationDao.queryById(train);
    }

    @Override
    public int queryByTrainId(TrainNumber trainNumber) {
        List<StopoverStation> stopoverStationList = stopoverStationDao.queryById(trainNumber.getTrain());
        int price = 0;
        for (StopoverStation s : stopoverStationList) {
            if (s.getSiteOrder()>=trainNumber.getStartOrder()&&s.getSiteOrder()<=trainNumber.getDestinationOrder()){
                price = price + s.getTrain().getMileagePrice() * s.getUnit().getMileage();
            }
        }
        return price;
    }

}

